﻿using Day27Auth.Data;
using Day27Auth.Models;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Day27Auth.Adapters.Data
{
    public class TodoDataAdapter : ITodoAdapter
    {
        public List<TodoViewModel> GetTodoViewModels(string userId)
        {
            List<TodoViewModel> models = null;

            using(ApplicationDbContext db = new ApplicationDbContext())
            {
                models = db.Todos.Where(t => t.UserId == userId).Select(t => new TodoViewModel
                {
                    Message = t.Message,
                    Subject = t.Subject,
                    Timestamp = t.Timestamp,
                    TodoId = t.TodoId,
                    Username = t.User.UserName
                }).ToList();
            }

            return models;
        }
    }
}